package com.miaodiyun.httpApiDemo;

import java.net.URLEncoder;
import java.util.Random;

import com.miaodiyun.httpApiDemo.common.Config;
import com.miaodiyun.httpApiDemo.common.HttpUtil;

/**
 * 验证码通知短信接口
 * 
 * @ClassName: IndustrySMS
 * @Description: 验证码通知短信接口
 *
 */
public class IndustrySMS{
	private static String operation = "/industrySMS/sendSMS";

	private static String accountSid = Config.ACCOUNT_SID;
//	private static String to = "13752350039";
	private static int  suijishu;
	//private static String smsContent = "【腾飞网络】登录验证码："+execute()+"，如非本人操作，请忽略此短信。";

	/**
	 * 验证码通知短信
	 * @return 
	 */
	public static int execute(String phone){
		String tmpSmsContent = null;
	    try{
	    	suijishu = suijishu();
	      tmpSmsContent = URLEncoder.encode("【腾飞网络】登录验证码："+suijishu +"，如非本人操作，请忽略此短信。", "UTF-8");
	    }catch(Exception e){
	      
	    }
	    String url = Config.BASE_URL + operation;
	    String body = "accountSid=" + accountSid + "&to=" + phone + "&smsContent=" + tmpSmsContent
	        + HttpUtil.createCommonParam();

	    // 提交请求
	    String result = HttpUtil.post(url, body);
	    System.out.println("result:" + System.lineSeparator() + result);
	    return suijishu;
	}
	public static int suijishu() {
		Random rand = new Random();
		int[] arr = new int[6];
		for (int i = 0; i < 6; i++) {
			arr[i] = rand.nextInt(10);
		}
		int x = 0;
		for (int i = 0; i < 6; i++) {

			x = (int) (x + arr[i] * Math.pow(10, i));
		}
		return x;
	}
}
